// 云函数 addDrawRecord
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

.0
exports.main = async (event, context) => {
  const { OPENID } = cloud.getWXContext();
  const { limit = 10, skip = 0 } = event;

  try {
    const res = await db.collection('drawRecords')
      .where({ _openid: OPENID })
      .orderBy('createTime', 'desc')
      .skip(skip)
      .limit(limit)
      .get();

    return {
      code: 0,
      data: res.data
    };
  } catch (err) {
    return {
      code: 1,
      msg: '查询失败',
      error: err
    };
  }
};
